home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #14 / Monster Media No. 14 (April 1996) (Monster Media, Inc.).ISO / prog_gen / instal11.zip / LECTURE.PAS < prev    next >
Pascal/Delphi Source File  |  1996-01-11  |  17KB  |  638 lines

  1. (**********************************)
  2. (* Lecture du fichier INSTALL.INS *)
  3. (**********************************)
  4. unit Lecture;
  5.  
  6. interface
  7.  
  8. uses Dialogs;
  9.  
  10. const Title_Parag : array [1 .. 8] of string =
  11.                     ('INFORMATION', (* Info about program to install       *)
  12.                      'DISKS',       (* Number of disk                      *)
  13.                      'ORIGIN',      (* Origin informations                 *)
  14.                      'DESTINATION', (* Destination informations            *)
  15.                      'GROUP',       (* Groups to create                    *)
  16.                      'ICONS',       (* Icons to create                     *)
  17.                      'FILES',       (* Files to copy                       *)
  18.                      'RUN');        (* Files to run                        *)
  19.       Number_Para = 8;              (* number of <> paragrafs              *)
  20.       lgn_Remarks = ';';            (* ligne en remarque                   *)
  21.       lgn_Paragrf = '[';            (* marque de paragraphe                *)
  22.       lgn_EqualSi = '=';            (* marque de debut des parametres      *)
  23.       lgn_Separat = ',';            (* marque de separateur des parametres *)
  24.       lgn_Pat_Red = '%';            (* marque d'indicateur de repertoire   *)
  25.       lgn_Pat_Trg = '1';            (* repertoire de destination           *)
  26.       lgn_Pat_Win = 'W';            (* repertoire de Windows               *)
  27.       lgn_Pat_Sys = 'S';            (* repertoire de Windows/System        *)
  28.       lgn_Pat_Rot = 'R';            (* repertoire racine                   *)
  29.  
  30. (* lecture du fichier d'install *)
  31. function ReadInsFile : integer;
  32.          {00 : File readed OK
  33.           01 : InsFile not found
  34.           02 : Unabled to open InsFile
  35.           03 : Unabled to read one line
  36.           04 : Wrong paragraf title
  37.           05 : Wrong line because = sign not found
  38.           06 : Wrong line because paragrf not found
  39.           07 : Wrong line in a information paragraf
  40.           08 : Wrong line in a disks paragraf
  41.           09 : Wrong line in a origin paragraf
  42.           10 : Wrong line in a destination paragraf
  43.           11 : Wrong line in a group paragraf
  44.           12 : Wrong line in a icons paragraf
  45.           13 : Wrong line in a files paragraf
  46.           14 : Wrong line in a run paragraf
  47.           15 : Wrong number in Num parameter
  48.           16 : Wrong number before = sign
  49.           17 : Wrong parameters in a Group line
  50.           18 : Wrong parameters in a Icons line
  51.           19 : Wrong parameters in a Files line
  52.           20 : Wrong parameters in a Run line
  53.           21 : Wrong number in a Dsk line}
  54.  
  55. function ReadUnsFile : integer;
  56.          { 0 : OK Uninstall readed correctly
  57.            1 : File doesn't exist
  58.            2 : Unable to read one line
  59.            3 : Error on number in line
  60.            4 : Maximum of file reach
  61.            5 : Wrong number in line}
  62.  
  63. implementation
  64.  
  65. uses SysUtils,Decla,Disque;
  66.  
  67. (*********************************)
  68. (* mise en majuscule de la ligne *)
  69. (*********************************)
  70. function MajusculeLigne (Ligne : string) : string;
  71. var bcl : integer;
  72.     tmp : string;
  73. begin
  74.  tmp := '';
  75.  for bcl := 1 to length (Ligne) do
  76.   Tmp := Tmp + upcase (Ligne [bcl]);
  77.  MajusculeLigne := Tmp;
  78. end;
  79.  
  80. (*******************************)
  81. (* traitements des lignes lues *)
  82. (*******************************)
  83.  
  84. (* analyse du nombre de disque *)
  85. function Traitement_NombreDsk (Ligne : string) : boolean;
  86. var Tmp : boolean;
  87.     Err : integer;
  88. begin
  89.  Tmp := true;
  90.  val (Ligne,Disk_Number,Err);
  91.  Tmp := (Disk_Number > 0) and (Err = 0);
  92.  Traitement_NombreDsk := Tmp;
  93. end;
  94.  
  95. (* analyse du disque *)
  96. function Traitement_Disque (Ligne : string;Numero : integer) : boolean;
  97. begin
  98.  with VPath [Numero] do
  99.   LettDriv := Ligne [1];
  100.  Traitement_Disque := true;
  101. end;
  102.  
  103. (* analyse du chemin *)
  104. function Traitement_Chemin (Ligne : string;Numero : integer) : boolean;
  105. begin
  106.  with VPath [Numero] do
  107.   PathDriv := Ligne;
  108.  Traitement_Chemin := true;
  109. end;
  110.  
  111. (* prendre les parametres *)
  112. function Coupe (var Ligne : string) : string;
  113. var Tmp : string;
  114. begin
  115.  Tmp := '';
  116.  Tmp := copy (Ligne,1,pos (lgn_Separat,Ligne) - 1);
  117.  Delete (Ligne,1,pos (lgn_Separat,Ligne));
  118.  Coupe := Tmp;
  119. end;
  120.  
  121. (* analyse d'une ligne de groupe *)
  122. function Traitement_Groupe (Ligne : string;Numero : integer) : boolean;
  123. var Tmp : boolean;
  124.     Lg1 : string;
  125.     Lg2 : string;
  126. begin
  127.  Tmp := true;
  128.  Delete (Ligne,1,pos (lgn_EqualSi,Ligne));
  129.  Lg1 := Coupe (Ligne);
  130.  Lg2 := Ligne;
  131.  if Numero > Max_Group then
  132.   Tmp := false
  133.  else
  134.  begin
  135.   if not ((Lg1 = '') or (Lg2 = '')) then
  136.   begin
  137.    With VGroup [Numero] do
  138.    begin
  139.     GroupName := Lg1;
  140.     GroupFile := MajusculeLigne (WinDir) + '\' + MajusculeLigne (Lg2);
  141.    end;
  142.   end
  143.   else
  144.    Tmp := False;
  145.  end;
  146.  Traitement_Groupe := Tmp;
  147. end;
  148.  
  149. (* analyse d'une ligne d'icone *)
  150. function Traitement_Icone (Ligne : string;Numero : integer) : boolean;
  151. var Tmp : boolean;
  152.     Lg1 : string;
  153.     Lg2 : string;
  154.     Lg3 : string;
  155.     lg4 : string;
  156.     Num : integer;
  157.     Err : integer;
  158. begin
  159.  Tmp := true;
  160.  Delete (Ligne,1,pos (lgn_EqualSi,Ligne));
  161.  Lg1 := Coupe (Ligne);
  162.  Lg2 := Coupe (Ligne);
  163.  Lg3 := Coupe (Ligne);
  164.  Lg4 := Ligne;
  165.  Val (Lg1,Num,Err);
  166.  if not ((Lg1 = '') or (Lg2 = '') or
  167.          (Lg3 = '') or (Lg4 = '')) then
  168.  begin
  169.   With VIcons [Numero] do
  170.   begin
  171.    DiskNumb := Num;
  172.    FileName := MajusculeLigne (Lg2);
  173.    if Lg3 [1] = lgn_Pat_Red then
  174.    begin
  175.     case Lg3 [2] of
  176.      lgn_Pat_Trg : FilePath := '%1';
  177.      lgn_Pat_Win : FilePath := MajusculeLigne (WinDir);
  178.      lgn_Pat_Sys : FilePath := MajusculeLigne (SysDir);
  179.     end;
  180.    end
  181.    else
  182.     FilePath := MajusculeLigne (Lg3);
  183.    IconName := Lg4;
  184.   end;
  185.  end
  186.  else
  187.   Tmp := False;
  188.  Traitement_Icone := Tmp;
  189. end;
  190.  
  191. (* analyse d'une ligne de fichier *)
  192. function Traitement_Fichier (Ligne : string;Numero : integer) : boolean;
  193. var Tmp : boolean;
  194.     Lg1 : string;
  195.     Lg2 : string;
  196.     Lg3 : string;
  197.     Num : integer;
  198.     Err : integer;
  199. begin
  200.  Tmp := true;
  201.  Delete (Ligne,1,pos (lgn_EqualSi,Ligne));
  202.  Lg1 := Coupe (Ligne);
  203.  Lg2 := Coupe (Ligne);
  204.  Lg3 := Ligne;
  205.  Val (Lg1,Num,Err);
  206.  if Numero > Max_Files then
  207.   Tmp := false
  208.  else
  209.  begin
  210.   if not ((Lg1 = '') or (Lg2 = '') or (lg3 = '')) then
  211.   begin
  212.    With VFiles [Numero] do
  213.    begin
  214.     DiskNumb := Num;
  215.     FileName := MajusculeLigne (Lg2);
  216.     if Lg3 [1] = lgn_Pat_Red then
  217.     begin
  218.      case Lg3 [2] of
  219.       lgn_Pat_Trg : FilePath := '%1';
  220.       lgn_Pat_Win : FilePath := MajusculeLigne (WinDir);
  221.       lgn_Pat_Sys : FilePath := MajusculeLigne (SysDir);
  222.      end;
  223.     end
  224.     else
  225.      FilePath := MajusculeLigne (Lg3);
  226.    end;
  227.   end
  228.   else
  229.    Tmp := False;
  230.  end;
  231.  Traitement_Fichier := Tmp;
  232. end;
  233.  
  234. (* analyse d'une ligne de lancement *)
  235. function Traitement_Run (Ligne : string;Numero : integer) : boolean;
  236. var Tmp : boolean;
  237.     Lg1 : string;
  238.     Lg2 : string;
  239.     Lg3 : string;
  240.     Lg4 : string;
  241. begin
  242.  Tmp := true;
  243.  Delete (Ligne,1,pos (lgn_EqualSi,Ligne));
  244.  Lg1 := Coupe (Ligne);
  245.  Lg2 := Coupe (Ligne);
  246.  Lg3 := Coupe (Ligne);
  247.  Lg4 := Ligne;
  248.  if Numero > Max_Run then
  249.   Tmp := false
  250.  else
  251.  begin
  252.   if not ((Lg1 = '') or (lg2 = '') or (lg3 = '') or (lg4 = '')) then
  253.   begin
  254.    With VRun [Numero] do
  255.    begin
  256.     FileName := MajusculeLigne (Lg1);
  257.     if Lg2 [1] = lgn_Pat_Red then
  258.     begin
  259.      case Lg2 [2] of
  260.       lgn_Pat_Trg : FilePath := '%1';
  261.       lgn_Pat_Win : FilePath := MajusculeLigne (WinDir);
  262.       lgn_Pat_Sys : FilePath := MajusculeLigne (SysDir);
  263.      end;
  264.     end
  265.     else
  266.      FilePath := MajusculeLigne (Lg2);
  267.     DocsName := MajusculeLigne (Lg3);
  268.     if Lg4 [1] = lgn_Pat_Red then
  269.     begin
  270.      case Lg4 [2] of
  271.       lgn_Pat_Trg : DocsPath := '%1';
  272.       lgn_Pat_Win : DocsPath := MajusculeLigne (WinDir);
  273.       lgn_Pat_Sys : DocsPath := MajusculeLigne (SysDir);
  274.      end;
  275.     end
  276.     else
  277.      DocsPath := MajusculeLigne (Lg4);
  278.    end;
  279.   end
  280.   else
  281.    Tmp := false;
  282.  end;
  283.  Traitement_Run := Tmp;
  284. end;
  285.  
  286. (* initialisation des variables *)
  287. procedure Initialise;
  288. var Bcl : integer;
  289. begin
  290.  for Bcl := 1 to Max_Group do
  291.  begin
  292.   With VGroup [Bcl] do
  293.   begin
  294.    GroupName := '';
  295.    GroupFile := '';
  296.   end;
  297.  end;
  298.  for Bcl := 1 to Max_Icons do
  299.  begin
  300.   With VIcons [Bcl] do
  301.   begin
  302.    DiskNumb := 0;
  303.    FileName := '';
  304.    FilePath := '';
  305.    IconName := '';
  306.   end;
  307.  end;
  308.  for Bcl := 1 to Max_Files do
  309.  begin
  310.   With VFiles [Bcl] do
  311.   begin
  312.    DiskNumb := 0;
  313.    FileName := '';
  314.    FilePath := '';
  315.   end;
  316.  end;
  317.  for Bcl := 1 to Max_Run do
  318.  begin
  319.   With VRun [Bcl] do
  320.   begin
  321.    FileName := '';
  322.    FilePath := '';
  323.    DocsName := '';
  324.    DocsPath := '';
  325.   end;
  326.  end;
  327.  for Bcl := 1 to Max_Path do
  328.  begin
  329.   With VPath [Bcl] do
  330.   begin
  331.    LettDriv := 'C';
  332.    PathDriv := '';
  333.   end;
  334.  end;
  335. end;
  336.  
  337. (**********************)
  338. (* lecture du fichier *)
  339. (**********************)
  340. function ReadInsFile : integer;
  341. var Tmp : integer;
  342.     Fch : System.Text;
  343.     Lgn : string;
  344.     LTm : string;
  345.     Bcl : integer;
  346.     Nbr : integer;
  347.     Lop : integer;
  348.     Err : integer;
  349.     Nb1 : integer;
  350.     Par : integer;      (* 1=Inf  2=Dsk  3=Org  4=Trg *)
  351.                         (* 5=Grp  6=Ico  7=Fil  8=Run *)
  352. begin
  353.  Tmp := 0;
  354.  Par := 0;
  355.  Initialise;
  356.  if ExistFile (Fch_Ins) = 0 then
  357.   Tmp := 1
  358.  else
  359.  begin
  360.   assign (Fch,Fch_Ins);
  361.   {$I-}; reset (Fch); {$I+};
  362.   if ioresult <> 0 then
  363.    Tmp := 2
  364.   else
  365.   begin
  366.    while not (eof (Fch)) do
  367.    begin
  368.     {$I-}; readln (fch,Lgn); {$I+};
  369.     if ioresult <> 0 then
  370.      Tmp := 3
  371.     else
  372.     begin
  373.      if (lgn <> '') and (Lgn [1] <> lgn_Remarks) then
  374.      begin
  375.       if Lgn [1] = lgn_Paragrf then
  376.       (* calculer le nouveau paragraphe *)
  377.       begin
  378.        Par := 0;
  379.        Ltm := MajusculeLigne (copy (Lgn,2,length (Lgn) - 2));
  380.        for Bcl := 1 to Number_Para do
  381.         if Ltm = Title_Parag [Bcl] then Par := Bcl;
  382.        if Par = 0 then
  383.         Tmp := 4;
  384.       end
  385.       else
  386.       (* ligne a traiter *)
  387.       begin
  388.        if pos (lgn_EqualSi,lgn) = 0 then
  389.         Tmp := 5
  390.        else
  391.        begin
  392.         Ltm := MajusculeLigne (copy (Lgn,1,pos (Lgn_EqualSi,Lgn) - 1));
  393.         Delete (lgn,1,pos (lgn_EqualSi,Lgn));
  394.         case Par of
  395.          1 : (* information *)
  396.              begin
  397.               if Ltm = 'TITLE' then Title := Lgn
  398.               else
  399.                if Ltm = 'SUBTITLE' then SubTitle := Lgn
  400.               else
  401.                if Ltm = 'VERSION' then Version  := Lgn
  402.               else
  403.                if Ltm = 'AUTHOR' then Author := Lgn
  404.               else
  405.                if Ltm = 'COPYRIGHT' then Copyright := Lgn
  406.               else
  407.                Tmp := 7;
  408.              end;
  409.          2 : (* disks       *)
  410.              begin
  411.               if Ltm = 'DSK' then
  412.               begin
  413.                if Traitement_NombreDsk (Lgn) = false then
  414.                 Tmp := 21;
  415.               end
  416.               else
  417.                Tmp := 8;
  418.              end;
  419.          3 : (* origin      *)
  420.              begin
  421.               if Ltm = 'ODSK' then Traitement_Disque (Lgn,1)
  422.               else
  423.                if Ltm = 'OPAT' then Traitement_Chemin (Lgn,1)
  424.               else
  425.                Tmp := 9;
  426.              end;
  427.          4 : (* destination *)
  428.              begin
  429.               if Ltm = 'DDSK' then Traitement_Disque (Lgn,2)
  430.               else
  431.                if Ltm = 'DPAT' then Traitement_Chemin (Lgn,2)
  432.               else
  433.                Tmp := 10;
  434.              end;
  435.          5 : (* group       *)
  436.              begin
  437.               if Ltm = 'NUM' then
  438.               begin
  439.                val (Lgn,Nbr,Err);
  440.                if (Nbr = 0) or (Err <> 0) then
  441.                 Tmp := 15
  442.                else
  443.                begin
  444.                 Number_group := Nbr;
  445.                 for Lop := 1 to Nbr do
  446.                 begin
  447.                  {$I-}; readln (Fch,Lgn); {$I+};
  448.                  if ioresult <> 0 then
  449.                   Tmp := 3
  450.                  else
  451.                  begin
  452.                   val (copy (Lgn,1,pos (lgn_EqualSi,Lgn) - 1),Nb1,Err);
  453.                   if Nb1 <> Lop then
  454.                    Tmp := 16
  455.                   else
  456.                    if Traitement_Groupe (Lgn,Nb1) = false then
  457.                     Tmp := 17;
  458.                  end;
  459.                 end;
  460.                end;
  461.               end
  462.               else
  463.                Tmp := 11;
  464.              end;
  465.          6 : (* icons       *)
  466.              begin
  467.               if Ltm = 'NUM' then
  468.               begin
  469.                val (Lgn,Nbr,Err);
  470.                if (Nbr = 0) or (Err <> 0) then
  471.                 Tmp := 15
  472.                else
  473.                begin
  474.                 Number_Icons := Nbr;
  475.                 for Lop := 1 to Nbr do
  476.                 begin
  477.                  {$I-}; readln (Fch,Lgn); {$I+};
  478.                  if ioresult <> 0 then
  479.                   Tmp := 3
  480.                  else
  481.                  begin
  482.                   val (copy (Lgn,1,pos (lgn_EqualSi,Lgn) - 1),Nb1,Err);
  483.                   if Nb1 <> Lop then
  484.                    Tmp := 16
  485.                   else
  486.                    if Traitement_Icone (Lgn,Nb1) = false then
  487.                     Tmp := 18;
  488.                  end;
  489.                 end;
  490.                end;
  491.               end
  492.               else
  493.                Tmp := 12;
  494.              end;
  495.          7 : (* files       *)
  496.              begin
  497.               if Ltm = 'NUM' then
  498.               begin
  499.                val (Lgn,Nbr,Err);
  500.                if (Nbr = 0) or (Err <> 0) then
  501.                 Tmp := 15
  502.                else
  503.                begin
  504.                 Number_Files := Nbr;
  505.                 for Lop := 1 to Nbr do
  506.                 begin
  507.                  {$I-}; readln (Fch,Lgn); {$I+};
  508.                  if ioresult <> 0 then
  509.                   Tmp := 3
  510.                  else
  511.                  begin
  512.                   val (copy (Lgn,1,pos (lgn_EqualSi,Lgn) - 1),Nb1,Err);
  513.                   if Nb1 <> Lop then
  514.                    Tmp := 16
  515.                   else
  516.                    if Traitement_Fichier (Lgn,Nb1) = false then
  517.                     Tmp := 19;
  518.                  end;
  519.                 end;
  520.                end;
  521.               end
  522.               else
  523.                Tmp := 13;
  524.              end;
  525.          8 : (* run         *)
  526.              begin
  527.               if Ltm = 'NUM' then
  528.               begin
  529.                val (Lgn,Nbr,Err);
  530.                if (Nbr = 0) or (Err <> 0) then
  531.                 Tmp := 15
  532.                else
  533.                begin
  534.                 Number_Run := Nbr;
  535.                 for Lop := 1 to Nbr do
  536.                 begin
  537.                  {$I-}; readln (Fch,Lgn); {$I+};
  538.                  if ioresult <> 0 then
  539.                   Tmp := 3
  540.                  else
  541.                  begin
  542.                   val (copy (Lgn,1,pos (lgn_EqualSi,Lgn) - 1),Nb1,Err);
  543.                   if Nb1 <> Lop then
  544.                    Tmp := 16
  545.                   else
  546.                    if Traitement_Run (Lgn,Nb1) = false then
  547.                     Tmp := 20;
  548.                  end;
  549.                 end;
  550.                end;
  551.               end
  552.               else
  553.                Tmp := 14;
  554.              end;
  555.         else
  556.          Tmp := 6;
  557.         end;
  558.        end;
  559.       end;
  560.      end;
  561.     end;
  562.    end;
  563.    Close (Fch);
  564.   end;
  565.  end;
  566.  ReadInsFile := Tmp;
  567. end;
  568.  
  569. (* lecture fichier de deinstallation *)
  570. function ReadUnsFile : integer;
  571. var Tmp : integer;
  572.     Fch : System.Text;
  573.     Lgn : string;
  574.     Num : integer;
  575.     Err : integer;
  576.     Oth : string;
  577.     Ite : integer;
  578. begin
  579.  Tmp := 0;
  580.  For Ite := 1 to Max_Unin do
  581.  begin
  582.   with VUnins [Ite] do
  583.   begin
  584.    TypeCase := -1;
  585.    FullName := '';
  586.   end;
  587.  end;
  588.  assign (Fch,Fch_UnIns + 'INS');
  589.  {$I-}; Reset (Fch); {$I+};
  590.  if IoResult <> 0 then
  591.  (* file doesn't exist *)
  592.   Tmp := 1
  593.  else
  594.  begin
  595.   Ite := 0;
  596.   while not (eof (Fch)) do
  597.   begin
  598.    {$I-}; Readln (Fch,Lgn); {$I+};
  599.    if ioresult <> 0 then
  600.    (* unable to read *)
  601.     Tmp := 2
  602.    else
  603.    begin
  604.     (* takes number *)
  605.     val (copy (Lgn,1,pos (',',lgn) - 1),Num,Err);
  606.     if Err <> 0 then
  607.     (* not a number *)
  608.      Tmp := 3
  609.     else
  610.     begin
  611.      if Ite > Max_Unin then
  612.      (* out of range *)
  613.       Tmp := 4
  614.      else
  615.      begin
  616.       (* assign names of files etc ... *)
  617.       case Num of
  618.        0,1,2 : (* Correct type *)
  619.                begin
  620.                 Inc (Ite);
  621.                 VUnins [Ite].TypeCase := Num;
  622.                 VUnins [Ite].FullName := copy (Lgn,pos (',',Lgn) + 1,
  623.                                                length (Lgn) - Pos (',',Lgn) + 1);
  624.                end;
  625.       else
  626.       (* wrong number *)
  627.        Tmp := 5;
  628.       end;
  629.      end;
  630.     end;
  631.    end;
  632.   end;
  633.  end;
  634.  ReadUnsFile := Tmp;
  635. end;
  636.  
  637. end.
  638.